function rest=maxL2err(u,term)

n=floor((size(u,1)+1.25)/term);    h=1/n;
gaussian=@(z) 1/sqrt(2*pi)*exp(-z.^2/2);

switch term
    case 1
        u0p=u(1:n); 
        
    case 2
        u0p=u(1:n);   u1p=u(n+1:2*n);
    case 3
        u0p=u(1:n);   u1p=u(n+1:2*n);     u2p=u(2*n+1:3*n); 
        
    case 4
        u0p=u(1:n);           u1p=u(n+1:2*n);     
        u2p=u(2*n+1:3*n);     u3p=u(3*n+1:4*n);
        err = zeros(n,1);
        for ii=1:n
            x=ii*h;
            errorhd=@(z) (log(1+z*x)./log(1+z) ...
                 - u0p(ii) - u1p(ii)*z - u2p(ii)/sqrt(2)*(z.^2-1) ...
                 - u3p(ii)/sqrt(6)*(z.^3-3*z)).^2;
            tmphd=@(z) errorhd(z).*gaussian(z);
            for nn=-10^4:10:10^4-10
                err(ii)=err(ii)+quadl(tmphd,nn,nn+10,10^-10);
            end
        end
        rest=sqrt(max(err));        
end